package com.wlw.util.response;


import com.wlw.util.util.ResponseCodeEnum;
import lombok.Data;

/**
 * ..
 * 通用相应结果
 *
 * @author
 * @since 2019-07-23 15:40
 */
@Data
public class CommonResponse {

    /**
     * 结果标识
     */
    private int code;
    /**
     * 提示信息
     */
    private String message;
    /**
     * 业务数据
     */
    private Object data;

    /**
     * 成功响应模型
     *
     * @return 响应模型
     */
    public static CommonResponse success() {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.code = ResponseCodeEnum.SUCCESS.getCode();
        commonResponse.message = "ok";
        commonResponse.data="";
        return commonResponse;
    }

    /**
     * 构建未授权响应模型
     *
     * @return 未授权响应模型
     */
    public static CommonResponse unauthorised() {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.code = ResponseCodeEnum.UNAUTHORISED.getCode();
        commonResponse.message = "无权限操作";
        return commonResponse;
    }

    /**
     * 构建无权访问响应模型
     *
     * @return 无权访问响应
     */
    public static CommonResponse forbidden() {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.setCode(ResponseCodeEnum.FORBIDDEN.getCode());
        commonResponse.setMessage("无权限操作");
        return commonResponse;
    }


    /**
     * 构建服务器内部错误响应模型
     *
     * @return 内部错误响应模型
     */
    public static CommonResponse serverError() {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.code = ResponseCodeEnum.SERVERERROR.getCode();
        commonResponse.message = "系统繁忙";
        return commonResponse;
    }
    /**
     * 构建服务器内部错误响应模型
     *
     * @return 内部错误响应模型
     */
    public static CommonResponse serverErrorMsg(String msg) {
        CommonResponse commonResponse = new CommonResponse();
        commonResponse.code = ResponseCodeEnum.SERVERERROR.getCode();
        commonResponse.message = msg;
        return commonResponse;
    }
}
